home *** CD-ROM | disk | FTP | other *** search
/ PC Graphics Unleashed / PC Graphics Unleashed.iso / ch01 / ati_16md.asm < prev    next >
Assembly Source File  |  1994-05-14  |  16KB  |  578 lines

  1. ;--------------------------------------------------------------------------
  2. ; This is file ATI_16M.ASM,  Version 0.3
  3. ;
  4. ; Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5. ; Copyright (C) 1992 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
  6. ; Copyright (C) 1994 Bernhard Schwall (ATI-parts)
  7. ;
  8. ; This file is distributed under the terms listed in the document
  9. ; "copying.dj", available from DJ Delorie at the address above.
  10. ; A copy of "copying.dj" should accompany this file; if not, a copy
  11. ; should be available from where this file was obtained.  This file
  12. ; may not be distributed without a verbatim copy of "copying.dj".
  13. ;
  14. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  15. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. ;--------------------------------------------------------------------------
  17. ;
  18. ; changes:
  19. ;
  20. ; Version 0.1:    07.02.1994
  21. ;    first release
  22. ;
  23. ; Version 0.2:    09.02.1994
  24. ;    fixed the byte/line to really needed size, so 640x480x16.7mio
  25. ;    will fit in 1MB-Ram
  26. ;    clear 2.MB when using 16.7mio. colormode
  27. ;
  28. ; Version 0.3:    16.02.1994
  29. ;    return the right number of planes
  30. ;    changed 24 bit mode to BGR-order
  31. ;    so disp160 will run in truecolor
  32. ;    
  33. ; Version 0.31: 31.03.1994
  34. ;       set screenwidth to original value when switching to textmode
  35. ;       changed the standard setup: disable memory aperture
  36. ;       changed grdriver.inc to new verson shipped with LIBGRX 1.03 which
  37. ;            now uses disp180 too.
  38. ;
  39. ;--------------------------------------------------------------------------
  40.  
  41. include grdriver.inc
  42. cseg    segment byte public 'code'
  43.     assume  cs:cseg, ds:cseg, es:cseg, ss:nothing
  44.  
  45.  
  46. ;--------------------------------------------------------------------------
  47. ; DRIVER HEADER
  48. ;  The following entries MUST match the structure and constant
  49. ;  declarations in the file 'grdriver.h' of the GRX graphics library
  50. ;  The mode word should contain the following bitfields:
  51. ;     - the GRD_NEW_DRIVER bit set for any new format driver
  52. ;     - the adapter type field should be specified
  53. ;     - the memory size field should be specified
  54. ;     - the paging mode field should be specified
  55. ;  The mode set routine will OR in the plane bitfield as it will
  56. ;  change when different color number modes are requested.
  57. ;--------------------------------------------------------------------------
  58.  
  59.     dw    offset mode_set_routine
  60.     dw    offset paging_routine
  61. mode_W  dw    GRD_NEW_DRIVER+GRD_VGA+GRD_1024K+GRD_RW_64K
  62. ;
  63. ; The 'def_xx' fields are filled in by go32 from the corresponding
  64. ; fields of the 'GO32' environment variable
  65. ;
  66. def_tw  dw    80        ; text width
  67. def_th  dw    25        ; text height
  68. def_gw  dw    640        ; graphics width
  69. def_gh  dw    480        ; graphics height
  70. def_nc  dw    16        ; graphics colors
  71.     dw    offset driver_init_routine
  72.     dw    offset text_mode_table
  73.     dw    offset graphics_mode_table
  74.  
  75. ;
  76. ; Biggest text and graphics sizes
  77. ;
  78. Max_TW  equ    80
  79. Max_TH  equ    50
  80. Max_GWn equ    800        ; non interlaced!!!
  81. Max_GHn equ    600
  82. Max_GW  equ    1024        ; may be interlaced
  83. Max_GH  equ    768
  84.  
  85. ;--------------------------------------------------------------------------
  86. ; TABLE OF SUPPORTED TEXT MODES
  87. ;    - keep sorted by size
  88. ;    - end with an all 0 entry
  89. ;    - BIOS field = 0xff disables it
  90. ;    - fields:
  91. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  92. ;--------------------------------------------------------------------------
  93. text_mode_table        label word
  94.     dw    80,    25,    2,    007h +  00000h
  95.     dw    40,    25,    16,    001h +  00000h
  96.     dw    80,    25,    16,    003h +  00000h
  97.     dw    80,    28,    16,    003h +  00100h
  98.     dw    80,    50,    16,    003h +  00200h
  99.     dw    132,    25,    16,    023h +  00000h
  100.     dw    132,    28,    16,    023h +  00100h
  101.     dw    132,    44,    16,    033h +  00000h
  102.     dw    0,    0,    0,    000h +  00000h
  103.  
  104. ;--------------------------------------------------------------------------
  105. ; TABLE OF SUPPORTED GRAPHICS MODES
  106. ;    - keep sorted first by colors then by size
  107. ;    - end with an all 0 entry
  108. ;    - BIOS field = 0xff disables it
  109. ;    - fields:
  110. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  111. ;--------------------------------------------------------------------------
  112. graphics_mode_table    label word
  113.     dw    320,    200,    16,    00dh +  00000h
  114.     dw    640,    200,    16,    00eh +  00000h
  115.     dw    640,    350,    16,    010h +  00000h
  116.     dw    640,    480,    16,    012h +  00000h
  117.     dw    800,    600,    16,    054h +  00000h
  118.     dw    1024,    768,    16,    055h +  00000h
  119.     dw    320,    200,    256,    013h +  00000h
  120.     dw    640,    400,    256,    061h +  00000h
  121.     dw    640,    480,    256,    062h +  00000h
  122.     dw    800,    600,    256,    063h +  00000h
  123.     dw    1024,    768,    256,    064h +     00000h
  124.     dw    640,    480,    32768,    062h +    00300h
  125.     dw    800,    600,    32768,    063h +    00300h
  126.     dw    1024,    768,    32768,    064h +    00300h
  127.     dw    640,    480,    49168,    062h +    00310h    ; 49168 = 0xc000+16
  128.     dw    800,    600,    49168,    063h +    00310h
  129.     dw    1024,    768,    49168,    064h +    00310h
  130.     dw    640,    480,    49176,    062h +  00380h    ; 49176 = 0xc000+24
  131.     dw    800,    600,    49176,    063h +    00380h
  132.     dw    0,    0,    0,    000h +  00000h
  133.  
  134. ;--------------------------------------------------------------------------
  135. ; TABLE OF SPECIAL SETUP PROCEDURES
  136. ;  You may need such procedures for:
  137. ;     -- reloading fonts on standard EGA or VGA for
  138. ;     higher resolution text modes
  139. ;     -- enable HiColor mode of some Super VGAs
  140. ;     -- Handle the parameter passing conventions of the VESA BIOS
  141. ;     -- put VGA into 256 color plane mode ("MODE X")
  142. ;     -- etc...
  143. ;  There should be one entry in the table for every non-zero
  144. ;  'setup_procedure_index' in the text and graphics mode tables.
  145. ;  The first entry in the table belongs to index 100h, and so on.
  146. ;  The special setup procedure is invoked via a near call.
  147. ;
  148. ;  Entry: DI=address of the mode record from the text or graphics
  149. ;      table to set up.
  150. ;
  151. ;  Exit:  Adapter configured
  152. ;      BX=driver mode word as it should be returned by the mode set
  153. ;         routine. Typically it involves picking up the mode word
  154. ;         from the header and OR-ing in the appropriate bitplane mode
  155. ;         bitfield. (This is not needed for text modes)
  156. ;      AX, SI can be trashed, PRESERVE DI!!!!
  157. ;
  158. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  159. ;--------------------------------------------------------------------------
  160. special_setup_table    label word
  161.     dw    offset  VGA_28row_mode_set
  162.     dw    offset  VGA_50row_mode_set
  163.     dw    offset    ATI_setup        ; setup 15, 16 and 24 bit
  164. ;
  165. ; Routine to set up VGA 50 row mode
  166. ; interface is described above
  167. ;
  168. VGA_50row_mode_set    proc    near
  169.     mov    ax,03h            ; set 80x25 mode
  170.     int    10h
  171.     xor    bx,bx
  172.     mov    ax,1112h        ; load 8x8 font
  173.     int    10h
  174.     ret
  175. VGA_50row_mode_set    endp
  176.  
  177. VGA_28row_mode_set    proc    near
  178.     mov    ax,WORD PTR [di+6]    ; set 25 line mode
  179.     xor    ah,ah
  180.     int    10h
  181.     xor    bx,bx
  182.     mov    ax,1111h        ; load 8x14 font
  183.     int    10h
  184.     ret
  185. VGA_28row_mode_set    endp
  186.  
  187. ; Routine to initialize 16.7milion color mode on ATI GU+ GUpro
  188.  
  189. ATI_Accell db 0
  190. ATI_lo     dw 0
  191. ATI_hi     dw 0
  192.  
  193. ATI_setup    proc near
  194.     mov     ax,word ptr [di+6]
  195.     and     ax,006fh
  196.     int    10h            ; switch to graphicsmode
  197.     mov    cx,ax
  198.     and    ax,006fh
  199.     cmp    ax,63h
  200.     jl    No2MB
  201.     mov    dx,01ceh        ; get old value of ATI2E
  202.     mov    al,0aeh    
  203.     out    dx,al
  204.     inc    dx
  205.     in    al,dx
  206.     and    al,0f0h
  207.     or    al,05
  208.     out    dx,al            ; set read/write-bank to 2.MB
  209.     mov    ax,cx
  210.     int    10h            ; switch to graphicsmode second time
  211.                     ; to clear 2.MB
  212.     mov    dx,01ceh        ; get old value of ATI2E
  213.     mov    al,0aeh    
  214.     out    dx,al
  215.     inc    dx
  216.     in    al,dx
  217.     and    al,0f0h
  218.     out    dx,al            ; set read/write-bank to 1.MB
  219. No2MB:    mov    dx,52eeh
  220.     in    ax,dx
  221.     and    ax,007fh
  222.     mov    cl,7
  223.     shl    ax,cl
  224.     add    ax,0c000h
  225.     mov    ATI_hi,ax
  226.     mov    ax,0064h
  227.     mov    ATI_lo,ax        ; get Rom-Entry-Point
  228. ; select colordepth
  229.     mov    cl,byte ptr [di+6]
  230.     test    cl,80h
  231.     jz    No_888
  232.     mov    ah,07h            ; 888
  233.     mov    bx,GRD_24_PLANES
  234.     push    bx
  235.     jmp    SelRes
  236. No_888: test    cl,10h
  237.     jz    No_565
  238.     mov    ah,0dh            ; 565
  239.     mov    bx,GRD_16_R_PLANES
  240.     push    bx
  241.     jmp    SelRes
  242. No_565:    mov    ah,05h            ; 555
  243.     mov    bx,GRD_16_PLANES
  244.     push    bx
  245. ; select resolution
  246. SelRes: and    cl,6fh
  247.     cmp    cl,62h
  248.     jnz    No640
  249.     mov    al,21h            ; 640x480
  250.     jmp    SetRes
  251. No640:    cmp    cl,63h
  252.     jnz    No800
  253.     mov    al,01h            ; 800x600
  254.     jmp    SetRes
  255. No800:    mov    al,41h            ; 1024x768
  256. SetRes:    mov    bx,3
  257.     call    dword ptr [ATI_lo]    ; set resolution and colordepth
  258.     mov    ax,0068h
  259.     mov    ATI_lo,ax
  260.     mov    ax,1
  261.     call    dword ptr [ATI_lo]    ; initialize video mode
  262.     mov    dx,5eeeh
  263. ;    mov    al,02h            ; enable memory-aperture
  264.     mov    al,00h            ; disable memory-aperture
  265. ;    mov    ah,09h          ; memory aperture at MB 9
  266.     out    dx,ax
  267.     mov    ax,word ptr [di]
  268.     shr    ax,3
  269.     mov    dx,26eeh
  270.     out    dx,ax
  271.     mov    dx,76eeh
  272.     out    dx,ax
  273.     mov    ATI_Accell,1
  274.     pop    bx            ; driver mode word
  275. ;    mov    bx,GRD_16_PLANES    ; comment out to use with disp180
  276.     or    bx,mode_W
  277.     mov    ax,0
  278.     ret
  279. ATI_setup    endp
  280.  
  281. ; switch ATI to SVGA-compatilbe mode
  282.  
  283. ATI_DisableAccell    proc near
  284.     mov    dx,52eeh
  285.     in    ax,dx
  286.     and    ax,007fh
  287.     mov    cl,7
  288.     shl    ax,cl
  289.     add    ax,0c000h
  290.     mov    ATI_hi,ax
  291.     mov    ax,0064h
  292.     mov    ATI_lo,ax
  293.     mov    ax,0
  294.     mov    bx,3
  295.     call    dword ptr [ATI_lo]
  296.     mov    ax,0068h
  297.     mov    ATI_lo,ax
  298.     mov    ax,0
  299.     call    dword ptr [ATI_lo]
  300.     mov    dx,5eeeh
  301.     mov    ax,0900h      ; memory aperture disabled
  302.     out    dx,ax
  303.     mov    dx,01ceh    ; get old value of ATI2E
  304.     mov    al,0aeh    
  305.     out    dx,al
  306.     inc    dx
  307.     in    al,dx
  308.     and    al,0f0h
  309.     out    dx,al        ; set read/write-bank to 1.MB
  310.     mov    ax,1024        ; set screenwidth to 1024 (original value)
  311.     shr    ax,3
  312.     mov    dx,26eeh
  313.     out    dx,ax
  314.     mov    dx,76eeh
  315.     out    dx,ax
  316.     mov    ATI_Accell,0
  317.     ret
  318. ATI_DisableAccell    endp
  319.  
  320. ;--------------------------------------------------------------------------
  321. ; DRIVER INIT ROUTINE
  322. ;  called once after the driver is loaded
  323. ;  may do one or more of the followings:
  324. ;    - check for proper board type
  325. ;    - check amount of RAM on board, and:
  326. ;    -- update word in header to reflect correct amount
  327. ;    -- disable modes in the tables for which there is not enough RAM
  328. ;    - check for special equipment (HiColor DAC, etc...)
  329. ;
  330. ;  Entry: nothing
  331. ;
  332. ;  Exit:  AX=status:
  333. ;       non-zero: OK,
  334. ;       0: something went wrong (e.g. wrong adapter, etc..)
  335. ;      BX,CX,DX may be trashed
  336. ;
  337. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  338. ;--------------------------------------------------------------------------
  339. driver_init_routine    proc    far
  340.     mov    ax,1
  341.     ret
  342. driver_init_routine    endp
  343.  
  344. ;--------------------------------------------------------------------------
  345. ; MODE SET ROUTINE
  346. ;  sets up a text or graphics mode as close as possible to the one
  347. ;  reguested by the user with regard to number of colors and size.
  348. ;
  349. ;  Entry: AX=mode selection
  350. ;     0 = 80x25 text
  351. ;     1 = default text
  352. ;     2 = text CX cols by DX rows
  353. ;     3 = biggest text
  354. ;     4 = 320x200 graphics
  355. ;     5 = default graphics
  356. ;     6 = graphics CX width by DX height
  357. ;     7 = biggest non-interlaced graphics
  358. ;     8 = biggest graphics
  359. ;     9 = graphics BX colors, CX width by DX height
  360. ;
  361. ;  Exit: BX=driver mode flag
  362. ;     CX=width (in pixels or characters)
  363. ;     DX=height
  364. ;
  365. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  366. ;     YOU SHOULD NOT NEED TO CHANGE THIS ROUTINE AS IT IS PRETTY
  367. ;     MUCH TABLE DRIVEN
  368. ;--------------------------------------------------------------------------
  369. mode_set_routine    proc    far
  370.     push    ds
  371.     push    di
  372.     push    si
  373.     mov    si,cs
  374.     mov    ds,si
  375.     cmp    ax,9
  376.     jbe    DoIt
  377.     jmp    Exit
  378. DoIt:    add    ax,ax
  379.     mov    si,ax
  380.     jmp    WORD PTR mode_set_table[si]
  381. mode_set_table  label    word
  382.     dw    offset mode_0
  383.     dw    offset mode_1
  384.     dw    offset mode_2
  385.     dw    offset mode_3
  386.     dw    offset mode_4
  387.     dw    offset mode_5
  388.     dw    offset mode_6
  389.     dw    offset mode_7
  390.     dw    offset mode_8
  391.     dw    offset mode_9
  392. mode_0: mov    si,offset text_mode_table    ; 80x25 text
  393.     mov    bx,def_nc
  394.     mov    cx,80
  395.     mov    dx,25
  396.     jmp    Lookup
  397. mode_1: mov    si,offset text_mode_table    ; default text
  398.     mov    bx,def_nc
  399.     mov    cx,def_tw
  400.     mov    dx,def_th
  401.     jmp    Lookup
  402. mode_2: mov    si,offset text_mode_table    ; CX*DX text
  403.     mov    bx,def_nc
  404.     jmp    Lookup
  405. mode_3: mov    si,offset text_mode_table    ; biggest text
  406.     mov    bx,def_nc
  407.     mov    cx,Max_TW
  408.     mov    dx,Max_TH
  409.     jmp    Lookup
  410. mode_4: mov    si,offset graphics_mode_table    ; 320x200 graphics
  411.     mov    bx,def_nc
  412.     mov    cx,320
  413.     mov    dx,200
  414.     jmp    Lookup
  415. mode_5: mov    si,offset graphics_mode_table    ; default graphics
  416.     mov    bx,def_nc
  417.     mov    cx,def_gw
  418.     mov    dx,def_gh
  419.     jmp    Lookup
  420. mode_6: mov    si,offset graphics_mode_table    ; CX*DX graphics
  421.     mov    bx,def_nc
  422.     jmp    Lookup
  423. mode_7: mov    si,offset graphics_mode_table    ; biggest non-interlaced gr
  424.     mov    bx,def_nc
  425.     mov    cx,Max_GWn
  426.     mov    dx,Max_GHn
  427.     jmp    Lookup
  428. mode_8: mov    si,offset graphics_mode_table    ; biggest graphics
  429.     mov    bx,def_nc
  430.     mov    cx,Max_GW
  431.     mov    dx,Max_GH
  432.     jmp    Lookup
  433. mode_9: mov    si,offset graphics_mode_table    ; CX*DX graphics w/ BX colors
  434. ;
  435. ; At this point:
  436. ;   SI points to the table to search (text or graphics)
  437. ;   BX has colors
  438. ;   CX has width
  439. ;   DX has height
  440. ;
  441. Lookup: xor    ax,ax                ; last color number seen
  442. Find_C: cmp    [si+4],ax            ; last color number == this?
  443.     je    Same_C
  444.     jb    Prev_C                ; end of table -- use last color
  445.     cmp    BYTE PTR [si+6],0ffh        ; valid entry ?
  446.     je    Prev_C                ; not -- use last color
  447.     mov    ax,[si+4]            ; record color number
  448.     mov    di,si                ; start of entries w/ this color
  449.     cmp    ax,bx                ; enough colors ?
  450.     jae    Find_S
  451. Same_C: add    si,8
  452.     jmp    Find_C
  453. Prev_C: or    ax,ax                ; found any color at all?
  454.     je    Exit
  455. ;
  456. ; At this point:
  457. ;   DI points into the table to the first entry with the desired color
  458. ;      number (either it has enough colors or it is the highest color
  459. ;      number supported by the driver). Additionally, at least the
  460. ;      first (= smallest size) entry for this color is valid (has a
  461. ;      valid BIOS number).
  462. ;   AX has the color number adjusted for the driver
  463. ;   CX has width
  464. ;   DX has height
  465. ;
  466. Find_S: cmp    [di+4],ax            ; still the same color #?
  467.     jne    Prev_S
  468.     cmp    BYTE PTR [di+6],0ffh        ; valid entry ?
  469.     je    Prev_S
  470.     cmp    [di],cx
  471.     jb    Next_S
  472.     cmp    [di+2],dx
  473.     jae    GotIt
  474. Next_S: add    di,8
  475.     jmp    Find_S
  476. Prev_S: sub    di,8
  477. ;
  478. ; At this point:
  479. ;   DI points to the table entry we want to set up
  480. ;
  481. GotIt:  mov    ax,[di+6]            ; BIOS mode number
  482.     or    ah,ah                ; special ?
  483.     je    doBIOS
  484.     mov    al,ah
  485.     xor    ah,ah
  486.     dec    ax
  487.     add    ax,ax
  488.     mov    si,ax
  489.     call    WORD PTR special_setup_table[si]
  490.     jmp    RetVal
  491. doBIOS: 
  492. ;--------------- changed because AccellChip must be disabled if not used
  493.     push    ax
  494.     mov    al,ATI_Accell
  495.     cmp    al,0
  496.     jz    NoATI
  497.     call    ATI_DisableAccell
  498. NoATI:    pop    ax
  499. ;--------------- change end
  500.     int    10h
  501.     mov    bx,GRD_1_PLANE
  502.     cmp    WORD PTR [di+4],2        ; 2 colors ?
  503.     je    doFLAG
  504.     mov    bx,GRD_4_PLANES
  505.     cmp    WORD PTR [di+4],16        ; 16 colors ?
  506.     je    doFLAG
  507.     mov    bx,GRD_8_PLANES
  508.     cmp    WORD PTR [di+4],256        ; 256 colors ?
  509.     je    doFLAG
  510.     mov    bx,GRD_16_PLANES
  511.     cmp    WORD PTR [di+4],32768        ; 32K colors ?
  512.     je      doFLAG
  513.     mov    bx,GRD_PLANE_MASK        ; something is wrong!!
  514. doFLAG: or    bx,mode_W
  515. RetVal: mov    cx,[di]
  516.     mov    dx,[di+2]
  517. Exit:    pop    si
  518.     pop    di
  519.     pop    ds
  520.     ret
  521. mode_set_routine    endp
  522.  
  523. ;--------------------------------------------------------------------------
  524. ; PAGING ROUTINE
  525. ;
  526. ;  Entry: AH=read page
  527. ;      AL=write page
  528. ;
  529. ;  Exit: VGA configured.
  530. ;     AX,BX,CX,DX,SI,DI may be trashed
  531. ;
  532. ;  NOTE: This runs in protected mode!  Don't mess with the segment registers!
  533. ;     This code must be relocatable and may not reference any data!
  534. ;--------------------------------------------------------------------------
  535.     assume  ds:nothing, es:nothing
  536.  
  537. paging_routine  proc    far
  538.     mov    bx,ax        ; save ax;
  539.  
  540.     ; can't speed up by using only 1MB for SVGA-modes because test itself
  541.     ; would be to slow (data referenze not possible)
  542.     ; set bits 4 and 5 of read/write bank to access 2.-4. MB
  543.     and     al,30h
  544.     shr    al,4
  545.     and    ah,30h
  546.     shr    ah,2
  547.     or    ah,al        ; combine Read and Write-Planes
  548.     cmp    ah,0
  549.     mov    dx,01ceh    ; get old value of ATI2E
  550.     mov    al,0aeh    
  551.     out    dx,al
  552.     inc    dx
  553.     in    al,dx
  554.     and    al,0f0h
  555.     or    al,ah
  556.     out    dx,al        ; write new value
  557.  
  558.     and    bh,0fh        ; Read-plane on bits 0-3
  559.     mov    ah,bh
  560.     shr    ah,3        ; move bit 3 to bit 0;
  561.     shl    bh,5        ; move bits 0-2 to 5-7;
  562.     or    ah,bh
  563.  
  564.     and    bl,0fh        ; Write-plane on bits 0-3
  565.     shl    bl,1
  566.  
  567.     or    ah,bl        ; Combine Read and Write plane
  568.  
  569.     mov    dx,01ceh    ; ATI register
  570.     mov    al,0b2h        ; plane select
  571.     out    dx,ax
  572.     ret
  573. paging_routine  endp
  574.  
  575.  
  576. cseg    ends
  577.     end
  578.